//将请求封装到这里
import axios from "axios"

//解决跨域
// axios.defaults.headers.get['withCredentials'] = 'true';
// axios.defaults.baseURL = '/api'
// axios.get('https://music.163.com').then(
//     response => {
//         console.log(response)
//     },
//     error => {
//         console.log(error)
//     }
// )
// axios.defaults.headers.common['Access-Control-Allow-Origin'] = '*';

//获取轮播图的api
export function getBanner(type = 0) {
    return axios.get(`http://localhost:4000/banner?type=${type}`)
}

//获取歌单 limit是指取出歌单的数量，这里设置的是默认是10
export function getMusicList(limit = 10) {
    return axios.get(`http://localhost:4000/personalized?limit=${limit}`)
}

//获取歌单详情
// export function getPlayListDetail(id = 2761182502) {
//     return axios.get(`https://music.163.com/api/#/playlist?id=${id}`)
// }
// export function getPlayListDetail(id = 2761182502) {
//     return axios.get(`http://localhost:4000/playlist/detail?id=${id}`)
// }

export function getPlayList(id = 2761182502) {
    return axios.get(`http://localhost:4000/playlist/track/all?id=${id}&limit=10&offset=0`)
}

//phone login
export function phoneLogin(phone, password) {
    return axios.get(`http://localhost:4000/login/cellphone?phone=${phone}&password=${password} `)
}

//搜索歌曲
export function SearchMusic(keyword) {
    return axios.get(`http://localhost:4000/search?keywords=${keyword} `)
}

//获取歌曲详情
export function getMusicDetail(id) {
    return axios.get(`http://localhost:4000/song/detail?ids=${id}`)
}

//获取歌词
export function getMusicWords(id) {
    return axios.get(`http://localhost:4000/lyric?id=${id}`)
}

export default {
    phoneLogin, SearchMusic, getMusicDetail, getMusicWords
}
